import axios from './request'

/**
 * methods: 请求
 * @param url 请求地址
 * @param params 请求参数
 */
export default {
	get(url, params) {
		const config = {
			method: 'get',
			async: true,
			url: url,
		}
		if (params) config.params = params
		return axios(config)
	},
	post(url, params) {
		const config = {
			method: 'post',
			url: url,
		}
		if (params) config.data = params
		return axios(config)
	},
	upload(url, file) {
		const config = {
			method: 'post',
			url: url,
			headers: {
				'Content-Type': 'multipart/form-data',
			},
		}
		const data = new FormData()
		data.append('file', file)
		config.data = data
		return axios(config)
	},
	put(url, params) {
		const config = {
			method: 'put',
			url: url,
		}
		if (params) config.params = params
		return axios(config)
	},
	delete(url, params) {
		const config = {
			method: 'delete',
			url: url,
		}
		if (params) config.params = params
		return axios(config)
	},
}
